package com.yeqian.user.security;


import com.yeqian.entity.ResultJson;
import com.yeqian.user.entity.LoginConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yeqian
 * @Classname MyAuthenticationEntryPoint
 * @Description TODO 身份验证
 * @Date 2021/5/8 15:29
 */
@Component
@Slf4j
public class YeqAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResultJson.writeJSON(response,ResultJson.error(2010, LoginConstant.PLEASE_LOGIN_TRY_AGAININSUFFICIENT_PERMISSIONS));
    }
}
